/*
 *   This file is part of verbum.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * 	 Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 */
 
function onGlossaryContextMenu(grid, rowIndex, e) {
    e.stopEvent();
    grid.selModel.selectRow(rowIndex);
	if (grid.selModel.getSelected().id!="-1") {
	    var listContextMenu = new Ext.menu.Menu({
	    	items: [
	    		{
	    			iconCls: 'edit',
	    			text: _('Edit'),
	    			handler: function() {
						var ed = new Verbum.EditWindow({
							id: 'glossaryEd',
							autoLoad: getMainUrl('action=glossary&op=edit&id='+grid.selModel.getSelected().id),
							url: getMainUrl('action=glossary&op=save'),
							title: _('Editing...'),
				            width: 320,
				            height: 260,
				            iconCls: 'edit',	
				            focus: 'translation',								
						});
						ed.show();
						
						ed.on({
							'success': {
								fn: function (){
										grid.store.reload();
			    					}
							}
						});    				
	    			}
	    		},
	    	]
	    });
	    
	    listContextMenu.showAt(e.getXY());	
	}
}

Ext.apply(MyDesktop.Glossary.prototype, {
	addCreate: function() {
		return {
			iconCls: 'add',
			tooltip: _('Add new term'),
			text: _('Add'),
			handler: function() {
				var ed = new Verbum.EditWindow({
					id: 'glossaryEd',
					autoLoad: getMainUrl('action=glossary&op=new'),
					url: getMainUrl('action=glossary&op=save'),
					title: _('Add new term'),
		            width: 320,
		            height: 260,
		            iconCls: 'add',	
		            focus: 'eterm',								
				});
				ed.show();
			}
		}		
	},
	addEdit: function(grid) {
		grid.on('rowcontextmenu', 
			onGlossaryContextMenu);
	},
});
